package com.czd.support.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.czd.base.model.Paginate;
import com.czd.base.service.BaseService;
import com.czd.support.common.Configuration;
import com.czd.support.model.AgentAttachment;

@Service
public class AgentAttachmentService extends BaseService<AgentAttachment> {
	public Paginate queryForPaginate(AgentAttachment agentAttachment, String kw) {
		agentAttachment.setPageSize(Configuration.getInstance()
				.getDefault_page_size());
		agentAttachment.setWhere(" 1=1");
		if (StringUtils.isNotBlank(kw)) {
			agentAttachment.setWhere(agentAttachment.getWhere()
					+ " and (fileName like '%" + kw + "%'     )");
		}
		return this.queryForPaginate(sqlId("queryForPaginate"),
				sqlId("agentCount"), agentAttachment);
	}

	/**
	 * 查询明细
	 */
	public AgentAttachment findDtail(int id) {

		return this.selectOneById("findDtail", id);
	}

	/**
	 * 添加附件
	 */
	public void addAgent(AgentAttachment agentAttachment) {

		this.insert("addAgent", agentAttachment);

	}

	/**
	 * 根据文件名查询是否存在
	 */

	public List<AgentAttachment> findyName(String fileName) {
		return this.selectList("findyName", fileName);
	}

	public boolean insert(AgentAttachment agentAttachment) {
		return this.insert(sqlId("addAgent"), agentAttachment);
	}
	
	public boolean update(AgentAttachment agentAttachment){
		return this.insert(sqlId("update"), agentAttachment);
	}
	
	public boolean delete(int id){
		return this.delete(sqlId("delete"), id);
	}
}
